<?php

namespace App\Admin\Controllers;


use App\Http\Controllers\Controller;

class BaseController extends Controller
{
    public function __construct()
    {
        parent::__construct();
        \Admin::js('/plugins/sortable.js');
    }
    public function get()
    {
        $q = request('q');
        $model = $this->form()->model();
        $fillAble = $this->form()->model()->getFillable();

        if (in_array('nickname', $fillAble)) {
            $model = $model->where('nickname', 'like', "%$q%");
            $title = 'nickname';
        }
        if (in_array('title', $fillAble)) {
            $model = $model->where('title', 'like', "%$q%");
            $title = 'title';
        }
        return $model
            ->orWhere('id', $q)
            ->orderBy('id','desc')
            ->paginate(null, ['id', "$title as text"]);
    }
}